'use strict';

// 1.控制器是否存在
// 2.方法是否存在
// 3.成功响应时，验证返回空结果和非空结果处理
// 4.验证响应失败处理

describe('fbdApp template controller', function() {
  var $rootScope, $controller, $scope;
  var $shareData, $compile;


  beforeEach(module('fbdApp.templateModule'));
  beforeEach(module('templates'));
  beforeEach(inject(function(_$controller_, _$rootScope_, _shareData_,
    _$compile_) {
    $rootScope = _$rootScope_;
    $scope = _$rootScope_.$new();
    $shareData = _shareData_;
    $controller = _$controller_;
    $compile = _$compile_;
    // $shareData.fileName = 'ab1230c3.fbd'
  }));

  function createController() {
    return $controller('templateCtrl', {
      $scope: $scope,
      $compile: $compile,
      shareData: $shareData
    });
  }

  it('should be defined', function(done) {
    var controller = createController();
    expect(controller).not.toBe(null);
    expect($scope.newTemp).toBe(true);
    expect($scope.upload).toBe(false);
    expect($scope.addSubrule).toBe(false);
    expect($scope.isMainTemp).toBe(true);
    expect($scope.newTempToNext).toBeDefined();
    expect($scope.toNewTemp).toBeDefined();
    expect($scope.addNewRules).toBeDefined();
    return done();
  });

  describe('newTempToNext method', function() {
    it('Is main template', function(done) {
      var controller = createController();
      $scope.newTempToNext();
      $scope.$apply();
      expect($scope.newTemp).toBe(false);
      expect($scope.isMainRule).toBe(true);
      expect($scope.upload).toBe(true);
      return done();
      // expect()
    });

    it('Is not main template', function(done) {
      var controller = createController();
      $scope.isMainTemp = false;
      $scope.newTempToNext();
      $scope.$apply();
      expect($scope.newTemp).toBe(false);
      expect($scope.isMainRule).toBe(true);
      expect($scope.upload).toBe(false);
      expect($scope.addSubrule).toBe(true);
      return done();
      // expect()
    });

  });

  describe('toNewTemp method', function() {
    it('should be defined', function(done) {
      var controller = createController();
      $scope.toNewTemp();
      $scope.$apply();
      expect($scope.newTemp).toBe(true);
      expect($scope.upload).toBe(false);
      return done();
    });
  });

  describe('addNewRules method', function() {
    it('Is main rule', function(done) {
      var controller = createController();
      $scope.isMainRule = true;
      $scope.addNewRules();
      $scope.$apply();
      expect($scope.newTemp).toBe(false);
      expect($scope.upload).toBe(false);
      expect($scope.addSubrule).toBe(true);
      expect($scope.isMainRule).toBe(false);
      console.log();
      return done();
    });

    it('Is not main rule', function(done) {
      var controller = createController();
      // $scope.isMainRule = false;
      // $scope.addNewRules();
      // $scope.$apply();
      // expect($scope.newTemp).toBe(false);
      // expect($scope.upload).toBe(false);
      // expect($scope.addSubrule).toBe(true);
      // expect($scope.isMainRule).toBe(false);
      return done();
    });
  });

});
